/**
 * Created by admin on 2018/10/25.
 */
$(function(){
    showDiv(0);
    bindLaypage('page',0);

    //给机器设备的span绑定点击切换事件
    $(" .m-choose  span").mouseenter(function(){
        $(this).addClass('active').siblings().removeClass('active');
        var index = $(this).index() ;
        showDiv(index);
        bindLaypage('page',index);
    });

    function showDiv(a){
        $(".show .very-material:eq("+a+")").css('display','block').siblings(".very-material").hide();
    }


    function hideDivs(parentIndex, start, end){
        if(parentIndex === null){
            $(".material-intro").hide();
        }else{
            for(var i= start; i< end; i++){
                $(".very-material:eq("+parentIndex+")").find(".material-intro:eq("+i+")").hide();
            }
        }
    }

    function _showDivs(parentIndex, start, end){
        if(parentIndex === null) {
            $(".material-intro").show();
        }else{
            for(var i= start; i< end; i++){
                $(".very-material:eq("+parentIndex+")").find(".material-intro:eq("+i+")").show();
            }
        }

    }

    //分页
    function bindLaypage(htmlId,parentIndex){
        var length = $(".very-material:eq("+parentIndex+")>.material-intro").length;
        layui.use('laypage', function(){
            var laypage = layui.laypage;
            laypage.render({
                elem : htmlId,
                theme: '#f0d021; ',
                // first:'首页',
                //last:'尾页',
                prev:'上一页',
                next:'下一页',
                limit: 6,
                curr:location.hash.replace('#!fenye=','.show'),
                hash:'fenye',
                count : length,
                jump: function(obj){
                    //隐藏所有数据
                    hideDivs(parentIndex, 0,length);
                    var start = (obj.curr-1)*obj.limit;//(1-1)*6=0  (2-1)*6=6  >>>
                    var end =   obj.curr * obj.limit;//(1)*6=6     (2)*6=12   >>>
                    _showDivs(parentIndex, start,end);

                }
            })
        })
    }
});
